﻿using System.ComponentModel;
using QASPRibbon;
using QASPRibbon.Controls;

namespace QASPRibbonDemo.ContextualDemoWebPart
{
    [ToolboxItemAttribute(false)]
    public class ContextualDemoWebPart : ContextualWebPart
    {
        public override RibbonContextualGroup GetContextualGroupDefinition()
        {
            var contextualGroup = new RibbonContextualGroup("GroupId", "GroupTitle")
                {
                    Color = GetColor()
                };

            var tab = new RibbonTab("TabId", "QASPRibbon Tab");
            var tab2 = new RibbonTab("TabId2", "Inactive Tab");

            var group = new RibbonGroup("GroupId", "GroupTitle");
            var group2 = new RibbonGroup("GroupId2", "GroupTitle");

            var section = new RibbonGroupSection
                {
                    Type = RibbonSectionType.OneRow,
                    DisplayMode = RibbonDisplayMode.Image32AndCaption
                };
            var section2 = new RibbonGroupSection
            {
                Type = RibbonSectionType.OneRow,
                DisplayMode = RibbonDisplayMode.Image32AndCaption
            };

            var button = new RibbonButton("ButtonId", "ButtonTitle")
                {
                    Image = RibbonImageDefinition.Standard15(2, 5),
                    OnClientClick = "alert('ButtonId has been clicked!');"
                };

            section.Controls = new RibbonControl[] {button};

            group.Sections = new RibbonGroupSection[] { section };
            group2.Sections = new RibbonGroupSection[] { section2 };

            tab.Groups = new RibbonGroup[] { group };
            tab2.Groups = new RibbonGroup[] { group };

            contextualGroup.Tabs = new RibbonTab[] {tab};//,tab2};

            return contextualGroup;
        }


        private RibbonContextualColor GetColor()
        {
            
            var req = Page.Request.QueryString["Color"];
            if(string.IsNullOrEmpty(req))
                return RibbonContextualColor.None;
            switch (req)
            {
                case "1":
                    return RibbonContextualColor.DarkBlue;
                case "2":
                    return RibbonContextualColor.Green;
                case "3":
                    return RibbonContextualColor.LightBlue;
                case "4":
                    return RibbonContextualColor.Magenta;
                case "5":
                    return RibbonContextualColor.Orange;
                case "6":
                    return RibbonContextualColor.Purple;
                case "7":
                    return RibbonContextualColor.Teal;
                case "8":
                    return RibbonContextualColor.Yellow;
            }
            return RibbonContextualColor.None;
        }
    }
}